package com.sneakxy.mybase4j.platform.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.sneakxy.mybase4j.base.service.BaseService;
import com.sneakxy.mybase4j.platform.beans.Launcher;
import com.sneakxy.mybase4j.platform.provider.ILauncherProvider;
import com.sneakxy.mybatis.commons.repository.query.domain.CriteriaBuilder;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Service
public class LauncherService extends BaseService<Launcher, String, ILauncherProvider> implements ILauncherService {

	@Reference(version = "1.0.0")
	@Autowired(required = false)
	@Qualifier("launcherProvider")
	private ILauncherProvider provider;

	@Override
	public ILauncherProvider getProvider() {
		return this.provider;
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.ILauncherService#findBySearch(java.lang.String, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<Launcher> findBySearch(String search, Pageable pageable) {
		if(StringUtils.isBlank(search)) {
			return this.getProvider().findAll(pageable);
		}
		String value = new StringBuilder()
				.append("%")
				.append(StringUtils.trimToEmpty(search))
				.append("%").toString();
		CriteriaBuilder<Launcher> builder = new CriteriaBuilder<Launcher>(Launcher.class);
		builder.orLike("name", value);
		builder.orLike("module", value);
		builder.orLike("memo", value);
		return this.getProvider().findAll(builder.build(), pageable);
	}



	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.ILauncherService#findAllLauncherModules(java.lang.String)
	 */
	@Override
	public List<String> findAllLauncherModules(String account_id) {
		return this.getProvider().findAllLauncherModules(account_id);
	}



	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.ILauncherService#findAllLaunchers(java.lang.String)
	 */
	@Override
	public List<Launcher> findAllLaunchers(String account_id) {
		return this.getProvider().findAllLaunchers(account_id);
	}

}
